package com.logistics.inventory.entity.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;

import com.logistics.inventory.entity.model.InventorySave;
import com.logistics.inventory.entity.model.UpdStation;
import com.logistics.utils.bean.UserBean;
import com.logistics.utils.constants.Constants;
import com.logistics.utils.tool.DateUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 库存
 * </p>
 *
 * @author kaihan.wang
 * @since 2024-06-28
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("lgs_inventory")
public class Inventory implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    //托盘
    private String container;

    //托盘层级
    private Integer containerLevel;

    //是否是空托盘（0:非空，1:空托）
    private Boolean isEmpty;

    //agv车辆
    private String agv;

    //站点
    private String station;

    // 创建人组织编码
    private String createOrgCode;

    // 创建人部门编码
    private String createDepCode;

    // 创建人
    private String creator;

    // 创建时间
    private Date createTime;

    // 修改人
    private String updater;

    // 修改时间
    private Date updateTime;

    // 叠放数量车辆
    @TableField(exist = false)
    private String containerCount;

    public static Inventory build(String station){
        Inventory inventory = new Inventory();
        inventory.setStation(station);
        return inventory;
    }

    public static Inventory build(String station, boolean isEmpty, UserBean user){
        Inventory inventory = new Inventory();
        inventory.setStation(station);
        inventory.setIsEmpty(isEmpty);
        inventory.setUpdater(user.getUserCode());
        inventory.setUpdateTime(new Date());
        return inventory;
    }

    public static Inventory build(boolean isEmpty){
        Inventory inventory = new Inventory();
        inventory.setIsEmpty(isEmpty);
        return inventory;
    }

    public static Inventory build(UpdStation updStation, boolean isFlag){
        Inventory inventory = new Inventory();
        if(isFlag){
            inventory.setStation(updStation.getStationCode());
        }else{
            inventory.setContainer(updStation.getContainerCode());
        }
        inventory.setUpdater(updStation.getUpdater());
        inventory.setUpdateTime(DateUtils.stringToDateFormat(updStation.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
        return inventory;
    }

    public static Inventory build(InventorySave edit) {
        Inventory inventory= new Inventory();
        inventory.setId(edit.getId());
        inventory.setContainer(edit.getContainer());
        inventory.setContainerLevel(edit.getContainerLevel());
        inventory.setIsEmpty(edit.getIsEmpty());
        inventory.setAgv(edit.getAgv());
        inventory.setStation(edit.getStation());
        inventory.setCreateDepCode(edit.getCreateDepCode());
        inventory.setCreateOrgCode(edit.getCreateOrgCode());
        inventory.setCreator(edit.getCreator());
        inventory.setCreateTime(DateUtils.stringToDateFormat(edit.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
        inventory.setUpdater(edit.getUpdater());
        inventory.setUpdateTime(DateUtils.stringToDateFormat(edit.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
        return inventory;
    }

    public static Inventory build(String container, Integer containerLevel, Boolean isEmpty, String station, UserBean userBean) {
        Inventory inventory= new Inventory();
        inventory.setContainer(container);
        inventory.setContainerLevel(containerLevel);
        inventory.setIsEmpty(isEmpty);
        inventory.setAgv(null);
        inventory.setStation(station);
        inventory.setCreateOrgCode(userBean.getOrganization());
        inventory.setCreateDepCode(userBean.getDep());
        inventory.setCreator(userBean.getAccount());
        inventory.setCreateTime(new Date());
        inventory.setUpdater(userBean.getAccount());
        inventory.setUpdateTime(new Date());
        return inventory;
    }
}
